package com.kantboot.business.bp.repository;

import com.kantboot.business.bp.domain.entity.BusBpProblemCollection;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface BusBpProblemCollectionRepository extends JpaRepository<BusBpProblemCollection, Long> {

    /**
     * 根据用户ID和题目ID删除收藏
     * @param userId 用户ID
     * @param problemId 题目ID
     */
    @Transactional
    @Modifying
    @Query("DELETE FROM BusBpProblemCollection WHERE userId = :userId AND problemId = :problemId")
    void deleteByUserIdAndProblemId(Long userId, Long problemId);

    List<BusBpProblemCollection> findByUserIdAndProblemId(Long userId, Long problemId);

    /**
     * 根据用户id获取收藏
     */
    List<BusBpProblemCollection> findByUserId(Long userId);
}
